home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1269 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  57 lines

  1. Path: news.iag.net!news
  2. From: jatmon@iag.net (John R Buchan)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Locaton of an array?
  5. Date: 12 Jan 1996 18:28:44 GMT
  6. Organization: Internet Access Group, Orlando, Florida
  7. Message-ID: <4d698s$g4r@news.iag.net>
  8. References: <4d4iqk$hs3@overload.lbl.gov>
  9. NNTP-Posting-Host: pm1-orl25.iag.net
  10. X-Newsreader: WinVN 0.99.7
  11.  
  12. In article <4d4iqk$hs3@overload.lbl.gov>, mfaiguen says...
  13. >
  14. >I am sure this has been answered a million times by now, but could someody 
  15. help
  16. >me, please?
  17. >
  18. >I have an array in my program, and I need to find out the absolute location 
  19. in
  20. >memory where this array is located. 
  21. >I have tried to do it this way:
  22. >
  23. >#include <stdio.h>
  24. >
  25. >int main() {
  26. >    char arr[10];
  27. >    int addr;
  28. >
  29. >    printf("sizeof(char *) = %d\n", sizeof(char *));
  30. >    printf("sizeof(int) = %d\n", sizeof(int));
  31. >
  32. >    addr = arr;
  33.  
  34. Your compiler allowed this??  Try:
  35.  
  36. #include <stdio.h>
  37.  
  38. int main() 
  39.    {
  40.    char arr[10];
  41.    void *ptr = arr;
  42.    
  43.    printf( "The address of arr is: %p\n", (void*)arr);
  44.    printf( "The address of arr is: %p\n", ptr);
  45.  
  46.    return 0;
  47.    }
  48.  
  49. I believe the c.l.c faq (Frequently Asked Question) list has a discussion
  50. on this.  It is available for anonymous ftp from rtfm.mit.edu
  51. /pub/usenet/comp.lang.c.
  52.  
  53. -- 
  54. John R Buchan           -:|:-     Looking for that elusive FAQ?  ftp to:
  55. jatmon@mail.iag.net     -:|:-     rtfm.mit.edu /pub/usenet-by-group/....
  56.  
  57.